package com.hongsheng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hongsheng.mapper.LineMapper;
import com.hongsheng.pojo.Line;
import com.hongsheng.service.LineService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName:LineService
 * Description:
 *
 * @Author: 曾晋冠
 * @Version: 2022.3.2
 * @Create: 2023/8/12 - 13:25
 */
@Service
public class LineServiceImpl implements LineService {
    @Autowired
    private LineMapper lineMapper;

    /**
     * 查询全部
     * @return
     */
    @Override
    public List<Line> findAllLine() {
        return lineMapper.findAllLine();
    }

    /**
     * 添加
     * @param line
     * @return
     */
    @Override
    public Boolean insertLine(Line line) {
        return lineMapper.insertLine(line);
    }

    /**
     * 修改
     * @param line
     * @return
     */
    @Override
    public Boolean updateLine(Line line) {
        return lineMapper.updateLine(line);
    }

    /**
     * 删除
     * @param id
     * @return
     */

    @Override
    public Boolean deleteLine(Integer id) {
        return lineMapper.deleteLine(id);
    }

    /**
     * id查询
     * @param id
     * @return
     */
    @Override
    public Line findAllById(Integer id) {
        return lineMapper.findAllById(id);
    }

    @Override
    public IPage<Line> getPageLine(Integer currentPage, Integer pageSize, Line line) {
       IPage iPage=new Page(currentPage,pageSize);
        LambdaQueryWrapper<Line> wrapper=new LambdaQueryWrapper<>();
        wrapper.like(Strings.isNotEmpty(line.getStartAddress()),Line::getStartAddress,line.getStartAddress());
        wrapper.like(Strings.isNotEmpty(line.getEndAddress()),Line::getEndAddress,line.getEndAddress());
        return lineMapper.selectPage(iPage,wrapper);
    }
}
